package edu.ufop.vaadin.helloworld.dao;


import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Date;
import java.util.List;
import java.sql.Connection;

import org.openqa.selenium.html5.ResultSet;

import edu.ufop.vaading.helloworld.model.User;
import edu.ufop.vaadin.helloworld.ConnectionFactory;


public class LoginDao {
	private Connection connection;
	
	public LoginDao(){
		this.connection = new ConnectionFactory().getConnection();
	}
	
	public boolean insertUser(User usr){
		String sql = "insert into usuarios "+ "(email,password)" + "values(?,?)";
		
		try{
			PreparedStatement stmt = connection.prepareStatement(sql);
			
			stmt.setString(1, usr.getEmail());
			stmt.setString(2, usr.getPassword());
			stmt.execute();
			stmt.close();
			
		}catch(SQLException e){
			throw new RuntimeException(e);
			return false;
		}
		return true;
		
		
	}
	public boolean findUser(String login, String senha){
		Connection con=new ConnectionFactory().getConnection();
		PreparedStatement stmt = con.prepareStatement("select * from usuarios");
		
		ResultSet rs = (ResultSet) stmt.executeQuery();
		
		while(rs.next()){
			if (login.equals(rs.getString("email")) && senha.equals(rs.getString("senha"))){
					return true;
			}
			
		}
		
	}
	

}
